package com.jwong.test;

import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.LogWatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("java:S106")
public class PodLogExample {

  private static final Logger logger = LoggerFactory.getLogger(PodLogExample.class);

  public static void main(String[] args) {
    String namespace = "default";
    String podName = "mysql-master-794f68c967-xngpz";

    System.out.println("Log of pod " + podName + " in " + namespace + " is:");
    System.out.println("----------------------------------------------------------------");

    try (
      KubernetesClient client = new DefaultKubernetesClient();

      LogWatch watch = client.pods().inNamespace(namespace).withName(podName).tailingLines(10).watchLog(System.out)
    ) {
      Thread.sleep(5 * 1000L);
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
    }
  }
}
